package com.liang.pattern.store.impl;

import com.alibaba.fastjson.JSON;
import com.liang.pattern.store.ICommodity;
import org.itstack.demo.design.coupon.CouponResult;
import org.itstack.demo.design.coupon.CouponService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @author lsm
 * @ClassName CouponCommodity.java
 * @Description TODO
 * @createTime 2023年11月29日 14:56:00
 */
public class CouponCommodity implements ICommodity {

    Logger logger = LoggerFactory.getLogger(CouponCommodity.class);

    private CouponService couponService = new CouponService();
    @Override
    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) {

        CouponResult couponResult = couponService.sendCoupon(uId, commodityId, bizId);
        logger.info("请求参数[优惠券] => uId：{} commodityId：{} bizId：{} extMap：{}", uId, commodityId, bizId, JSON.toJSON(extMap));
        logger.info("测试结果[优惠券]：{}", JSON.toJSON(couponResult));
        if (!couponResult.getCode().equals("0000")) {
            throw new RuntimeException(couponResult.getInfo());
        }
    }
}
